package user;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

import org.omg.CORBA.ORB;

public class PlayerClient extends Thread {
	String serverName;
	BufferedWriter write;
	FileWriter writer;

	public static void main(String[] args) throws IOException {
		ORB orb = ORB.init(args, null);

		BufferedReader br1 = new BufferedReader(new FileReader("ior1.txt"));
		String ior1 = br1.readLine();
		br1.close();

		org.omg.CORBA.Object o1 = orb.string_to_object(ior1);
		corbainterface FrontE = corbainterfaceHelper.narrow(o1);

		int choice = 0;
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			System.out.println("Let's Begin!");
			while (true) {

				System.out.println("0. Create multiple new Game account automatically from System ");
				System.out.println("1. Create new Game account ");
				System.out.println("2. Sign In");
				System.out.println("3. Sign Out");
				System.out.println("4. Transfer Account");
				System.out.println("5. GetPlayerStatus");
				System.out.println("6. Suspend Account");
				System.out.println("7. Exit");
				choice = Integer.parseInt(br.readLine());

				if (choice == 0) {

					System.out.println(FrontE.createPlayerAccount("C", "D", "23", "cccccc", "dddddd",
							"93.32.32.32"));
					System.out.println(FrontE.createPlayerAccount("A", "B", "22", "aaaaaa", "bbbbbb",
							"132.32.32.32"));
					
					System.out.println(FrontE.createPlayerAccount("E", "F", "23", "eeeeee", "ffffff",
							"182.32.32.32"));
					
					System.out.println(FrontE.playerSignIn("cccccc", "dddddd", "93.32.32.32"));
					System.out.println(FrontE.playerSignIn("aaaaaa", "bbbbbb", "132.32.32.32"));				
					System.out.println(FrontE.playerSignIn("eeeeee", "ffffff", "182.32.32.32"));
					

				} else if (choice == 2) {

					Scanner sc = new Scanner(System.in);
					System.out.println("Enter the username : ");
					String Username = sc.next();
					System.out.println("Enter the password : ");
					String Password = sc.next();
					System.out.println("Enter the IP Address : ");
					String ipp = sc.next();
					if(sc!=null){
						sc.close();}
				System.out.println(	FrontE.playerSignIn(Username, Password, ipp));

				} else if (choice == 1) {

					Scanner scanner = new Scanner(System.in);
					System.out.println("Enter First Name: ");
					String First = scanner.next();
					System.out.println("Enter Last name: ");
					String Last = scanner.next();
					System.out.println("Enter the Age: ");
					String age = scanner.next();
					System.out.println("Enter the Username: ");
					String usename = scanner.next();
					System.out.println("Enter the Password: ");
					String pwd = scanner.next();

					System.out.println("Enter the  IP Address: ");
					String ip = scanner.next();
					if(scanner!=null){
						scanner.close();}
					System.out.println(FrontE.createPlayerAccount(First, Last, age, usename, pwd, ip));

				} else if (choice == 3) {

					Scanner scc = new Scanner(System.in);
					System.out.println("Enter the username :");
					String username = scc.next();
					System.out.println("Enter the IPAddress :");
					String IP = scc.next();
					if(scc!=null){
						scc.close();}
					System.out.println(FrontE.playerSignOut(username, IP));

				} else if (choice == 4) {

					Scanner scca = new Scanner(System.in);
					System.out.println("Enter the username :");
					String usernamme = scca.next();
					System.out.println("Enter the Password :");
					String passwordd = scca.next();
					System.out.println("Enter the old IPAddress");
					String oip = scca.next();
					System.out.println("Enter the new IPAddress");
					String nip = scca.next();
					if(scca!=null){
						scca.close();}
					System.out.println(FrontE.transferAccount(usernamme, passwordd, oip, nip));

				}else if(choice == 5){
					
					System.out.println(FrontE.getPlayerStatus("admin", "admin", "132.22.33.123"));
				}
				else if(choice == 6)
				
				{
				
					
					Scanner scca = new Scanner(System.in);
              		System.out.println("Enter username");
                    String User1 = scca.next();
                    System.out.println("Enter Password");
                    String Pass1 = scca.next() ;
              		System.out.println("Enter IP address");
                      String IP1 = scca.next();
                      System.out.println("Enter Username to Suspend");
                      String Suspend = scca.next();
                      if(scca!=null){
  						scca.close();}
                      System.out.println(FrontE.suspendAccount(User1, Pass1, IP1, Suspend)); 
              	}
				
				else if (choice == 7) {
					System.out.println("Cioa!");
					System.exit(0);
				}

			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
